package asn.match.dao;

import java.util.List;

import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import asn.match.model.AboutMember;

@Service("about_member")
@PersistenceContext(type = PersistenceContextType.EXTENDED)
@Transactional
public class AboutMemberDaoImpl implements AboutMemberDAO {

	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void addAboutMember(AboutMember aboutMember) {
		this.sessionFactory.getCurrentSession().save(aboutMember);
	}

	@Override
	public void updateAboutMember(AboutMember aboutMember) {
		this.sessionFactory.getCurrentSession().saveOrUpdate(aboutMember);
	}

	@Override
	public void deleteAboutMember(AboutMember aboutMember) {
		this.sessionFactory.getCurrentSession().delete(aboutMember);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AboutMember> findAllAboutMembers() {
		return (List<AboutMember>) this.sessionFactory.getCurrentSession().createQuery("from AboutMember about_member").list();
	}

	@Override
	public AboutMember findAboutMemberById(Integer aboutMemberId) {
		return (AboutMember) this.sessionFactory.getCurrentSession().get(AboutMember.class, aboutMemberId);
	}

}
